package leetcode.动态规划.middle;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

/**
 * @author wangmaolin1
 * @date 2022/1/16 下午5:20
 */
public class _22括号生成 {
    public static List<String> generateParenthesis(int n) {
        if (n == 1) {
            return Arrays.asList("()");
        }
        HashSet<String> set = new HashSet<>();
        StringBuilder sb;
        for (String str : generateParenthesis(n - 1)) {
            for (int i = 0; i < str.length() / 2; i++) {
                set.add(str.substring(0,i)+"()"+str.substring(i));
            }
        }
        return new ArrayList<>(set);


    }


    public static void main(String[] args) {
        //[ ()()(()), (((()))), (())()(), (())(())]
        //()(())()
        //(())  ()()  (())
        System.out.println(generateParenthesis(4));
    }


}
